package
{
      import com.pblabs.engine.PBE;
      import com.pblabs.engine.core.LevelManager;
import com.pblabs.engine.entity.IEntity;
import com.pblabs.engine.resource.SWFResource;
import com.pblabs.rendering2D.MovieClipRenderer;
import com.pblabs.rendering2D.ui.SceneView;

import flash.geom.Point;

// Set the initial size of the application, and define the
      // maximum frame rate
      [SWF(width="640", height="480", frameRate="60")]
      public class EntityDemo extends SceneView
      {
            public function EntityDemo()
            {
                  // Start the PushButton Engine
                  PBE.startup(this);
                  // Initialize some default PushButton components
                  PBE.initializeScene(this);
                  // Make the embedded resources available to PushButton
                  PBE.addResources(new ResourceDatabase());
                  // Register the components that will be referenced in
                  // the XML file
                  RegistrationDatabase.RegisterComponents();
                  // Define a callback Entity, which is a custom function that
                  // constructs a new Entity
                  PBE.defineEntityByFunction("MovieClipRendererDemo",
                        createMovieClipRendererEntity);
                  // Load level 1 as defined in the LevelDescriptions.xml
                  //file
                  LevelManager.instance.load("LevelDescriptions.xml", 1);
            }

            protected function createMovieClipRendererEntity():IEntity
            {
                  // Get the resource representing the embedded fountain.swf file
                  var resource:SWFResource = PBE.resourceManager.load("fountain.swf", SWFResource) as SWFResource;
                  // Allocate a new Entity
                  var entity:IEntity = PBE.allocateEntity();
                  // Initialize the Entity, with the common alias
                  entity.initialize(null, "DemoEntity");
                  // Create a new MovieClipRenderer Component
                  var component:MovieClipRenderer = new MovieClipRenderer();
                  // Set the scene
                  component.scene = PBE.scene;
                  // Assign the MovieClip from the SWFResource to the MovieClipRenderer Component
                  component.clip = resource.clip;
                  // Center the Component
                  component.position = new Point(320 - component.clip.width / 2, 240 - component.clip.height / 2);
                  // Add the Component to the Entity
                  entity.addComponent(component, "MovieClipRenderer");
                  // Return the Entity
                  return entity;
            }
      }
}